﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DLM.Infrastructure.Domain;
using System.Web.Mvc;

namespace DLM.Domain.Model
{
    public class Party : IValidatableObject, IAggregateRoot
    {
        public Party()
        {
            this.UserPartyAssociation = new HashSet<UserPartyAssociation>();
        }

        public int PartyID { get; set; }
        public int Status { get; set; }

        [Required(ErrorMessage = "活动类型不允许为空")]
        public int PartyType { get; set; }

        [Required(ErrorMessage = "活动主题不允许为空")]
        [StringLength(30, ErrorMessage = "最大长度为30")]
        public string Subject { get; set; }

        [StringLength(20, ErrorMessage = "最大长度为20")]
        public string PhotoUrl { get; set; }

        //[Required(ErrorMessage = "活动形式不允许为空")]
        [StringLength(20, ErrorMessage = "最大长度为20")]
        public string Modality { get; set; }

        [Required(ErrorMessage = "活动时间不允许为空")]
        [DataType(DataType.DateTime, ErrorMessage = "活动时间格式不正确")]
        //[RegularExpression(@"(1[0-2]|0?[1-9])[-./](0?[1-9]|[12][0-9]|3[01])[-./](dddd))", ErrorMessage = "活动时间格式不正确")]
        public Nullable<System.DateTime> PartyDate { get; set; }

        //[Required(ErrorMessage = "活动地点不允许为空")]
        [StringLength(80, ErrorMessage = "最大长度为80")]
        public string Location { get; set; }

         [Required(ErrorMessage = "详细地点不允许为空")]
        [StringLength(150, ErrorMessage = "最大长度为150")]
        public string Address { get; set; }

        [Required(ErrorMessage = "活动人数不允许为空")]
        [RegularExpression(@"^[1-9]\d*$", ErrorMessage = "参加人数必须为正整数")]
        public Nullable<int> MemberCount { get; set; }


        public System.DateTime CreateDate { get; set; }

        [Required(ErrorMessage = "活动结束时间不允许为空")]
        [DataType(DataType.DateTime, ErrorMessage = "活动结束时间格式不正确")]
        public DateTime EndDate { get; set; }


        [StringLength(50, ErrorMessage = "最大长度为50")]
        public string Area { get; set; }
        public bool IsSuccess { get; set; }

         [StringLength(200, ErrorMessage = "最大长度为200")]
         [Required(ErrorMessage = "活动内容不允许为空")]
        public string Content { get; set; }

        [Required(ErrorMessage = "费用不允许为空")]
        [RegularExpression(@"^(-?\d+)(\.\d+)?$", ErrorMessage = "费用格式不正确！")]
        public decimal Expense { get; set; }

        [Required(ErrorMessage = "支付类型不允许为空")]
        public int PaymentType { get; set; }


        public virtual ICollection<UserPartyAssociation> UserPartyAssociation { get; set; }


        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (PartyType < 0)
            {
                yield return new ValidationResult("聚会类型不允许为空", new string[] { "PartyType" });
            }

            if (!(PartyDate is DateTime))
            {
                yield return new ValidationResult("活动日期格式不准确", new string[] { "PartyDate" });
            }
        }
    }

    public enum PartyType
    {
        Sport = 0,
        Friend = 1,
        HomeTown = 2,
        Other = 3
    }

    public enum PartyStatus
    {
        PendingForApproval = 3,
        Open = 0,
        Closed = 1,
        Freeze = 2,
        Cancel = 4,
        Refuse = 5

    }

}
